<template>
  <BaseContainer>
    <aplid-base-crud ref="crud" class="w-100" v-bind="{...theConfig,...$attrs}">
      <template v-slot:menuColumn="{ row }">
        <el-button v-if="row.dataStatus && row.dataStatus !== '0'" @click="handleChange(row)" text type="warning"> 变更中
        </el-button>
      </template>
      <template v-slot:addDialog="{ row, show }">
        <TabForm @refresh="handleRefresh" @operate="handleOperate" :api="baseConfig.api" :key="show" :nowRowData="row" :paramsObj="{
          seniorLiving:1,
          seniorLivingLabel:'社区居家养老',
        }">
        </TabForm>
      </template>
      <template v-slot:RechangeDialog="{ row, show }">
        <Rechange @refresh="handleRefresh" :api="baseConfig.api" :key="show" :nowRowData="row"></Rechange>
      </template>
      <template v-slot:ArchivesDialog="{ row, show }">
        <Archives @refresh="handleRefresh" @refreshPage="handleRefreshPage" @rechange="handleOperate"
          :api="baseConfig.api" :key="show" :nowRowData="row"></Archives>
      </template>
      <template v-slot:importDialog="{ row, show }">
        <ImportForm @refresh="handleRefresh" :api="baseConfig.api" :key="show" :nowRowData="row" :paramsObj="{
          seniorLiving:1,
          seniorLivingLabel:'社区居家养老',
        }"></ImportForm>
      </template>
    </aplid-base-crud>

    <el-dialog v-model="dialogVisible" title="数据变更" width="65%">
      <RechangeDetail v-if="dialogVisible" @refresh="handleRefresh" :batchNumber="nowData.dataStatus"></RechangeDetail>
    </el-dialog>
  </BaseContainer>
</template>

<script setup lang="ts">
import {baseConfig, tableConfig,searchConfig } from './config'
import TabForm from './TabForm/index.vue'
import Archives from './Archives/index.vue'
import ImportForm from './ImportForm/index.vue'
import Rechange from './Rechange/index.vue'
import RechangeDetail from '@/views/datacenter/components/DataGather/change/detail.vue'
import { editConfig } from '@/views/datacenter/comprehensiveQueries/utils/index'

type Props = {
  isComprehensiveQueries?:boolean
}
let props = withDefaults(defineProps<Props>(),{
  isComprehensiveQueries:false,
})
let theConfig :any= ref({})
if(baseConfig){
  let defaultConfig = JSON.parse(JSON.stringify({
    ...baseConfig,
    tableConfig,
    searchConfig
  }))
  if(props.isComprehensiveQueries){
    theConfig.value = editConfig(defaultConfig)
  }else{
    theConfig.value = {
      ...baseConfig,
      tableConfig,
      searchConfig
    }
  }
  
}

const crud = ref()
let nowData: any = {}
const dialogVisible = ref(false)
const handleRefresh = (query, visible = false) => {
  dialogVisible.value = visible
  nextTick(() => {
    crud.value.refreshChange(query)
  })
}
const handleOperate = (type, row, title) => {
  console.log('返回',type, row, title)
  nextTick(() => {
    crud.value.handleOperate(type, row, title)
  })
}
const handleRefreshPage = () => {
  nextTick(() => {
    crud.value.refreshChange({}, true)
  })
}
const handleChange = (row) => {
  nowData = row
  dialogVisible.value = true
}
defineExpose({
  handleRefresh
})
</script>

<style lang="scss" scoped>

</style>
